home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1995, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* anti.c
- * This program draws two intersecting cubes and uses the
- * accumulation buffer to do scene antialiasing.
- *
- * <a> key - toggle scene antialiasing
- * Escape key - exit the program
- *
- * Note: this program must be compiled with accpersp.c and jitter.h
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <stdio.h>
- #include <math.h>
-
- #include "jitter.h"
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid animate( GLvoid );
- GLvoid visibility( GLint );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- GLvoid toggleJitter(GLvoid);
-
- GLvoid printHelp( char * );
-
- GLvoid accFrustum(GLdouble, GLdouble, GLdouble, GLdouble,
- GLdouble, GLdouble, GLdouble, GLdouble,
- GLdouble, GLdouble, GLdouble);
- GLvoid accPerspective(GLdouble, GLdouble, GLdouble, GLdouble,
- GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- static GLint maxJitters = 1;
- static GLdouble aspect = 1.0;
-
- static GLfloat angle = 0.0;
-
- GLvoid
- main(int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( width/4, height/4 );
- glutInitWindowSize( width/4, height/4 );
- glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_ACCUM );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutIdleFunc( animate );
- glutVisibilityFunc( visibility );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- GLvoid
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - use the accumulation buffer "
- "to antialias an entire scene.\n\n"
- "Expect it to run very slowly on systems without \n"
- "a hardware accumulation buffer.\n\n"
- "Escape key - exit the program\n"
- "<a> key - toggle scene antialiasing\n\n",
- progname );
-
- printf("scene antialiasing is OFF\n");
- }
-
- GLvoid
- initgfx(GLvoid)
- {
- GLfloat shiny_mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat shiny_mat_shininess[] = { 128.0 };
-
- glMaterialfv(GL_FRONT, GL_SPECULAR, shiny_mat_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, shiny_mat_shininess);
-
- glEnable(GL_DEPTH_TEST);
-
- glShadeModel(GL_FLAT);
-
- glEnable(GL_LIGHT0);
- glEnable(GL_LIGHTING);
-
- glColorMaterial(GL_FRONT, GL_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
-
- glClearColor( 0.0, 0.0, 0.0, 1.0 );
- glClearAccum( 0.0, 0.0, 0.0, 1.0 );
-
- glEnable(GL_DEPTH_TEST);
- }
-
- GLvoid
- toggleJitter(GLvoid)
- {
- maxJitters = ( maxJitters == 1 ? 8 : 1 );
-
- printf("scene antialiasing is %s\n", (maxJitters==1?"OFF":"ON"));
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case 'a': /* toggle jittering */
- toggleJitter();
- glutPostRedisplay();
- break;
- case KEY_ESC: /* Exit when the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- glViewport( 0, 0, width, height );
-
- aspect = (GLdouble) width/(GLdouble) height;
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glMatrixMode( GL_MODELVIEW );
- }
-
- GLvoid
- animate( GLvoid )
- {
- angle = fmodf( (angle + 5.0), 360.0 ); /* update angle */
- glutPostRedisplay(); /* Tell GLUT to redraw */
- }
-
- GLvoid
- visibility( int state )
- {
- if (state == GLUT_VISIBLE) {
- glutIdleFunc( animate );
- } else {
- glutIdleFunc( NULL );
- }
- }
-
- /* Draws two cubes with scene antialiasing */
- GLvoid
- drawScene(GLvoid)
- {
- int jitter;
-
- if ( maxJitters > 1 ) glClear(GL_ACCUM_BUFFER_BIT);
-
- for (jitter = 0; jitter < maxJitters; jitter++)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- accPerspective(30.0, aspect, 1.0, 15.0,
- j8[jitter].x, j8[jitter].y, 0.0, 0.0, 1.0);
- glTranslatef (0.0, 0.0, -8.0);
-
- glRotatef(angle, 1.0, 0.0, 0.0);
-
- glColor3f(0.9, 0.9, 0.9);
- glutSolidCube( 1.0 );
-
- glRotatef(45.0, 0.0, 1.0, 0.0);
- glRotatef(45.0, 0.0, 0.0, 1.0);
-
- glColor3f(0.9, 0.0, 0.9);
- glutSolidCube( 1.0 );
- glPopMatrix();
-
- if ( maxJitters > 1 ) glAccum(GL_ACCUM, 1.0/maxJitters);
- }
-
- if ( maxJitters > 1 ) glAccum(GL_RETURN, 1.0);
-
- glutSwapBuffers();
- }
-